var app = new Vue({
    el: '#app',
    data: {
		order: {},
		customerFile:[],
		serviceFile:[],
		spare:[],
		first:true
    },
    mounted: function () {
        this.$nextTick(function () {
           this.creatList();
        })
    },
    updated:function(){
		//初始加载时初始化video控件,first标记只要初始化一次就行
		if(app.first){
			for(var i in app.customerFile){
				if(app.customerFile[i].fileType === REPAIR_FILE_TYPE_VIDEO){
                    app.getFiles(app.customerFile[i].fileId);
				}else{
                    lightGallery(document.getElementById('c-'+app.customerFile[i].id));//客户上传的图片
                }
			}
			// for(var i in app.serviceFile){
			// 	if(app.serviceFile[i].fileType === REPAIR_FILE_TYPE_VIDEO){
            //         app.getFiles(app.serviceFile[i].fileId);
			// 	}else{
            //         lightGallery(document.getElementById('s-'+app.serviceFile[i].id));//维修人员上传的图片
            //     }
            // }
            $('.vjs-big-play-button').on('click', function(){
                console.log($(this).next().find('.vjs-fullscreen-control'));
                
                $(this).next().find('.vjs-fullscreen-control').click();
            });

            $('.vjs-play-control').on('click', function(){
                console.log($(this).parent('div'));
                
                $(this).parent('div').find('.vjs-fullscreen-control').click();
            });
            
            lightGallery(document.getElementById('sign-image')); //签名
            app.imgshow();
			app.first = false;
		}
	},
    methods: {
        imgshow: function () {
        //问题描述图片轮播及放大
            var swiper = new Swiper('.swiper-container', {
                slidesPerView: 4,
                spaceBetween: 30,
                pagination: {
                    el: '.swiper-pagination',
                    clickable: true,
                },
            });
        },
        creatList: function () {
        //初始化list数据，将岗位详情显示 
            let id = getUrlParam("id");
            Server.getFromCustomer('/searchRepairDetailById', {id: id}, function (result) {
                app.order = result.data.repair;
				app.spare = result.data.spare;
				app.customerFile = result.data.customerFile;
				app.serviceFile = result.data.serviceFile;
                //当工单为已提交时，获取全部经销商
                if(app.order.repairState === REPAIR_STATE_SUBMIT){
                    Server.getFromService('/listAgency',{type:0}, function(res){
                        if(res.code === 200){
                            let data = res.data;
                            let options = '';
                            for(var i in data){
                                options += '<option value="'+ data[i].id +'">'+ data[i].name +'</option>'
                            }
                            $('#selectMan').html(options);
                        }else{
                            alert("获取分配经销商出错！");
                        }
                    });
                }
            });
        },
        // 分配维修人员
        distribution:function() {
            console.log("hello");
            
            //首先获得下拉框的节点对象；
            let sel_id = $('#selectMan').val();
            let sel_name = $('.am-selected-status').text();
            let param = {
                repaieRecordId: app.order.id,
                serviceMan: sel_name,
                serviceUserId: sel_id
            }
            Server.postToManage('/allotOrder', param, function(res){
                if(res.code === 200){
                    app.order.repairState = REPAIR_STATE_AUDIT;
                    app.order.auditTime = res.data;
                    app.order.serviceUserName = sel_name;
                }
            });
        },
        // 关闭视频弹出层
        closeVideo: function () {
            $('.vjs-playing').click();
            document.getElementById("video_show").style.display = "none";
        },
        getFiles:function(fileID){
			var player = TCPlayer('f'+fileID, { // player-container-id 为播放器容器ID，必须与html中一致
                fileID: fileID, // 请传入需要播放的视频filID 必须
                appID: "1256187897", // 请传入点播账号的appID 必须
				autoplay: false //是否自动播放
                //其他参数请在开发文档中查看
            });
        },
        getCosFile(file){
            if(file){
                return COS_FILE_URL + encodeURI(file);
            }
        }
    }
});